package com.frxuexi.mdm2205.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

@Composable
fun Demo06() {
//1.创建 NavController
    val navController = rememberNavController()

    //startDestination:起始路径
    NavHost(navController = navController, startDestination = "main", builder = {
        composable("main") { MainPage(navController) }
        composable("sec/{myname}") {
            val name = it.arguments?.getString("myname", "")
            SecondPage(name!!)
        }
    })
}


@Composable
fun MainPage(navController: NavHostController) {
    Text(text = "主页面",
        Modifier
            .fillMaxSize()
            .background(Color.Yellow)
            .clickable {
                navController.navigate("sec/aa")
            }
    )
}

@Composable
fun SecondPage(name: String) {
    Text(
        text = "二页面$name",
        Modifier
            .fillMaxSize()
            .background(Color.Green)
    )
}


